#pragma once

#include <string>
#include <fstream>

class Util
{

public:
    static std::string getOneLine(std::string &buf, const std::string &sep)
    {
        // xxxxyyyy z\r\nxxxxy z\r\n
        auto pos = buf.find(sep);
        if ((pos == buf.npos))
            return nullptr;
        std::string line = buf.substr(0, pos);
        buf.erase(0, line.size() + sep.size()); // 把读到的行擦掉，包括\r\n
        return line;
    }

    static bool readFile(const std::string resource, std::string *out)
    {
        std::ifstream ifs(resource);
        if(!ifs.is_open()) return false;
        std::string line;
        while (getline(ifs, line))
        {
            *out += line;
        }
        ifs.close();
        return true;
    }
};
